package com.yuqian.JavaSe.redis;

import java.util.ResourceBundle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisConnectionException;

public class RedisProvider {  
	  
    protected static final Logger LOG = LoggerFactory.getLogger(RedisProvider.class);  
    protected static JedisPool jedispool;  
    protected static int EXPIRE = 130;  
    static{  
        ResourceBundle bundle = ResourceBundle.getBundle("redis");  
        if (bundle == null) {  
            throw new IllegalArgumentException(  
                    "[redis.properties] is not found!");  
        }  
  
        EXPIRE = Integer.valueOf(bundle.getString("redis.expire"));  
        jedispool = new JedisPool("127.0.0.1");
    }  
      
    public static Jedis getJedis() {  
        Jedis jedis = null;  
        try {  
            jedis = jedispool.getResource();  
        } catch (JedisConnectionException jce) {  
            ExceptionUtil.getTrace(jce);  
            try {  
                Thread.sleep(3000);  
            } catch (InterruptedException e) {  
                ExceptionUtil.getTrace(e);  
            }  
            jedis = jedispool.getResource();  
        }  
        return jedis;  
    }  
}  

